﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Talkng_head
{
    class FemaleHead : Head
    {
        Stopwatch timer;

        public FemaleHead(ServiceContainer services)
            : base(services)
        {
            timer = Stopwatch.StartNew();
            LoadModel();
        }

        public override void LoadModel()
        {
            model = content.Load<Model>("models\\female");
            MeasureModel();
        }

        public override void Draw(GraphicsDevice graphicsDevice)
        {
            if (model != null)
            {
                var bones = model.Bones;
                // Compute camera matrices.
                //float rotation = (float)timer.Elapsed.TotalSeconds;

                Vector3 eyePosition = modelCenter;

                eyePosition.Z += modelRadius + 10.5f;

                float aspectRatio = graphicsDevice.Viewport.AspectRatio;

                float nearClip = modelRadius / 100;
                float farClip = modelRadius * 100;

                Matrix world = Matrix.CreateWorld(modelCenter, new Vector3(1,0,0), Vector3.Up);
                Matrix view = Matrix.CreateLookAt(eyePosition, modelCenter, Vector3.Up);
                Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, aspectRatio,
                                                                    nearClip, farClip);
                
                // Draw the model.
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.World = boneTransforms[mesh.ParentBone.Index] * world;
                        effect.View = view;
                        effect.Projection = projection;

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;
                        effect.SpecularPower = 16;
                    }

                    mesh.Draw();
                }
            }
        }
    }
}
